ورود

View Full Version : یک تغییر کوچک در برنامه بازی



computer _ student
شنبه 24 دی 1390, 19:44 عصر
سلام
من یک برنامه بازی اسمبلی دارم که به این صورته:
بازیکن اول یک عدد حدس میزنه و بازیکن دوم بر اساس راهنمایی هایی که برنامه بهش میده (مثلا عدد حدس زده شده شما کوچکتر و یا بزرگتر است) عدد را حدس می زند.
حالا باید این برنامه را طوری تغییر بدم که player2 فقط قادر به 10 بار حدس زدن باشه
این کار را با یک مقایسه ساده بر روی تعداد حدس ها (که در cx ذخیره می شود) انجام دادم اما برنامه هیچ عکس العملی به این شرط نشان نمی دهد
باید چه کار کنم؟
; program to implement number guessing game
; author: R. Detmer
; date: revised 9/97

.386
.MODEL FLAT

INCLUDE io.h

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

cr EQU 0dh ; carriage return character
Lf EQU 0ah ; linefeed character

.STACK 4096 ; reserve 4096-byte stack

.DATA ; reserve storage for data
prompt1 BYTE cr,Lf,Lf,"Player 1, please enter a number: ", 0
target DWORD ?
clear BYTE 24 DUP (Lf), 0
prompt2 BYTE cr,Lf,"Player 2, your guess? ", 0
stringIn BYTE 20 DUP (?)
lowOutput BYTE "too low", cr, Lf, 0
highOutput BYTE "too high", cr, Lf, 0
gotItOutput BYTE "you got it", cr, Lf, 0
countLabel BYTE Lf, "Number of guesses:"
countOut BYTE 6 DUP (?)
BYTE cr, Lf, Lf, Lf, "Do you want to play again? ",0
higher10 BYTE "sorry,number of gusses is higher than 10", cr,Lf, 0
.CODE ; start of main program code
_start:

untilDone: output prompt1 ; ask player 1 for target
input stringIn, 20 ; get number
atod stringIn ; convert to integer
mov target,eax ; store target
output clear ; clear screen
mov cx, 0 ; zero count

untilMatch: inc cx ; increment count of guesses
cmp cx,10
je l1
mov DI,0
output prompt2 ; ask player 2 for guess
input stringIn, 20 ; get number
atod stringIn ; convert to integer
INC DI
cmp eax, target ; compare guess and target
jne ifLess ; guess = target ?
equal: output gotItOutput ; display "you got it"
jmp endCompare
ifLess: jnl isGreater ; guess < target ?
output lowOutput ; display "too low"
jmp endCompare
isGreater: output highOutput ; display "too high"
endCompare:
cmp eax, target ; compare guess and target
cmp DI,4
ja endUntilDone
jne untilMatch ; ask again if guess not = target

l1: output higher10
itoa countOut, cx ; convert count to ASCII
output countLabel ; display label, count and prompt
input stringIn, 20 ; get response
cmp stringIn, 'n' ; response = 'n' ?
je endUntilDone ; exit if so
cmp stringIn, 'N' ; response = 'N' ?
jne untilDone ; repeat if not
endUntilDone:
output gameover
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code

xman_1365_x
دوشنبه 26 دی 1390, 05:12 صبح
; program to implement number guessing game
; author: R. Detmer
; date: revised 9/97

.386
.MODEL FLAT

INCLUDE io.h

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD

cr EQU 0dh ; carriage return character
Lf EQU 0ah ; linefeed character

.STACK 4096 ; reserve 4096-byte stack

.DATA ; reserve storage for data
prompt1 BYTE cr,Lf,Lf,"Player 1, please enter a number: ", 0
target DWORD ?
clear BYTE 24 DUP (Lf), 0
prompt2 BYTE cr,Lf,"Player 2, your guess? ", 0
stringIn BYTE 20 DUP (?)
lowOutput BYTE "too low", cr, Lf, 0
highOutput BYTE "too high", cr, Lf, 0
gotItOutput BYTE "you got it", cr, Lf, 0
countLabel BYTE Lf, "Number of guesses:"
countOut BYTE 6 DUP (?)
BYTE cr, Lf, Lf, Lf, "Do you want to play again? ",0
higher10 BYTE "sorry,number of gusses is higher than 10", cr,Lf, 0
gameover byte cr,Lf,"Game over",cr,Lf,0

.CODE ; start of main program code
_start:

untilDone:
output prompt1 ; ask player 1 for target
input stringIn, 20 ; get number
atod stringIn ; convert to integer
mov target,eax ; store target
output clear ; clear screen
mov cx, 0 ; zero count

untilMatch:
inc cx ; increment count of guesses
cmp cx,10
je l1
mov DI,0
output prompt2 ; ask player 2 for guess
input stringIn, 20 ; get number
atod stringIn ; convert to integer
INC DI
cmp eax, target ; compare guess and target
jne ifLess ; guess = target ?
equal:
output gotItOutput ; display "you got it"
jmp l2 ;befor label endCompare
ifLess:
jnl isGreater ; guess < target ?
output lowOutput ; display "too low"
jmp endCompare
isGreater:
output highOutput ; display "too high"

endCompare:
cmp eax, target ; compare guess and target
cmp DI,4
ja endUntilDone
jne untilMatch ; ask again if guess not = target

l1:
output gameover
output higher10
l2:
itoa countOut, cx ; convert count to ASCII
output countLabel ; display label, count and prompt
input stringIn, 20 ; get response
cmp stringIn, 'n' ; response = 'n' ?
je endUntilDone ; exit if so
cmp stringIn, 'N' ; response = 'N' ?
jne untilDone ; repeat if not
endUntilDone:


INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code

موفق باشي

computer _ student
چهارشنبه 28 دی 1390, 16:47 عصر
ممنون از کمک شما
آیا خودتون برنامه را تست کردید که جواب می دهد یا نه؟ من اجرا کردم هیچ تفاوتی با قبل نکرده بود!!!!
دستور پرش مربوط به cx اصلا اجرا نمی شود
در مورد ثابت cr و lf چیزی می دونید؟ (cr را می دونم که کد اسکی کلید enter را ذخیره کرده اما lf ؟)
البته در برنامه ای که گذاشتم dl هم اضافه بود
دوباره برنامه را میگذارم
; program to implement number guessing game
; author: R. Detmer
; date: revised 9/97
.386
.MODEL FLAT
INCLUDE io.h
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
cr EQU 0dh ; carriage return character
Lf EQU 0ah ; linefeed character
.STACK 4096 ; reserve 4096-byte stack
.DATA ; reserve storage for data
prompt1 BYTE cr,Lf,Lf,"Player 1, please enter a number: ", 0
target DWORD ?
clear BYTE 24 DUP (Lf), 0
prompt2 BYTE cr,Lf,"Player 2, your guess? ", 0
stringIn BYTE 20 DUP (?)
lowOutput BYTE "too low", cr, Lf, 0
highOutput BYTE "too high", cr, Lf, 0
gotItOutput BYTE "you got it", cr, Lf, 0
countLabel BYTE Lf, "Number of guesses:"
countOut BYTE 6 DUP (?)
BYTE cr, Lf, Lf, Lf, "Do you want to play again? ",0
higher10 BYTE "sorry,number of gusses is higher than 10", cr, Lf, 0
.CODE ; start of main program code
_start:
untilDone: output prompt1 ; ask player 1 for target
input stringIn, 20 ; get number
atod stringIn ; convert to integer
mov target,eax ; store target
output clear ; clear screen
mov cx, 0 ; zero count
untilMatch: inc cx ; increment count of guesses
cmp cx,10
jl l1
output prompt2 ; ask player 2 for guess
input stringIn, 20 ; get number
atod stringIn ; convert to integer
cmp eax, target ; compare guess and target
jne ifLess ; guess = target ?
equal: output gotItOutput ; display "you got it"
jmp endCompare
ifLess: jnl isGreater ; guess < target ?
output lowOutput ; display "too low"
jmp endCompare
isGreater: output highOutput ; display "too high"
endCompare:
cmp eax, target ; compare guess and target
jne untilMatch ; ask again if guess not = target
jmp l2:
l1: output higher10
l2: itoa countOut, cx ; convert count to ASCII
output countLabel ; display label, count and prompt
input stringIn, 20 ; get response
cmp stringIn, 'n' ; response = 'n' ?
je endUntilDone ; exit if so
cmp stringIn, 'N' ; response = 'N' ?
jne untilDone ; repeat if not
endUntilDone:
INVOKE ExitProcess, 0 ; exit with return code 0
PUBLIC _start ; make entry point public
END ; end of source code